var offset = (document.documentElement["getBoundingClientRect"] ?
function (e) {
	var rect = e.getBoundingClientRect(), doc = e.ownerDocument,
		top = rect.top + (self.pageYOffset || doc.documentElement.scrollTop || doc.body.scrollTop),
		left = rect.left + (self.pageXOffset || doc.documentElement.scrollLeft || doc.body.scrollLeft);
	return { left : left, top : top };
} :
function (e) {
	var offsetParent = e.offsetParent, doc = e.ownerDocument, docElem = doc.documentElement, 
		defaultView = doc.defaultView, body = doc.body,
		prevElem = e, prevComputedStyle, top = e.offsetTop, left = e.offsetLeft;
	
	while ( (e = e.parentNode) && e != body) {
		top -= e.scrollTop, left -= e.scrollLeft;
		if (e === offsetParent) {
			e += offsetParent.offsetTop, left += offsetParent.offsetLeft;
			offsetParent = e.offsetParent;	
		}
		prevElem = e;
	}
	
	prevComputedStyle = defaultView.getComputedStyle(prevElem);
	if ("relative static".indexOf(prevComputedStyle.position) >= 0)
		top += body.offsetTop,
		left += body.offsetLeft;
	
	if (prevComputedStyle.position == 'fixed')
		top += Math.max(docElem.scrollTop, body.scrollTop),
		left += Math.max(docElem.scrollLeft, body.scrollTop);
	
	return { left : left, top : top };
});